<template>
  <div class="test-form">
    <h3 style="margin-bottom: 30px;">测试IFrame表单提交</h3>
<!--    <el-form-->
<!--        size="mini"-->
<!--        ref="submitForm"-->
<!--        :model="submitForm"-->
<!--        :rules="submitFormRules"-->
<!--        label-width="80px"-->
<!--    >-->
      <el-form
          size="mini"
          ref="submitForm"
          :model="submitForm"
          label-width="80px"
          :rules="submitFormRules"
      >
      <el-form-item label="组织编码" prop="organizeCode" >
        <el-input
            v-model.trim="submitForm.organizeCode"
            placeholder="请输入"
            clearable
        />
      </el-form-item>
        <el-form-item label="测试2" prop="organizeCode22">
          <el-input
              v-model.trim="submitForm.organizeCode22"
              placeholder="请输入"
              clearable
          />
        </el-form-item>
      <el-form-item label="数据值" prop="fieldValue">
        <el-input-number v-model="submitForm.fieldValue" :min="1" :max="999999999" label="请输入" style="width: 100%"></el-input-number>
      </el-form-item>
      <div class="btn">
        <el-button type="primary" @click="handleSubmitForm" size="mini"
        >确定</el-button
        >
        <el-button @click="resetForm" size="mini">重置</el-button>
      </div>
    </el-form>
  </div>
</template>
<script>
import { savaIframeApi } from "@/api/testForm";
import * as verify from "../utils/verify.js";
export default {
  name: "TestForm",
  components: {},
  data() {
    return {
      submitForm: {},
      submitFormRules: {
        organizeCode:[verify.inputRequired(),verify.maxLength(10)],
        fieldValue:[
          {
            required: true,
            message: `请输入`,
          }
        ]
      },
      sexArr: [
        {
          label:`男`,
          value: `1`,
        },
        {
          label:`女`,
          value: `2`,
        },
      ],
    };
  },
  computed: {},
  created() {
    if(this.$route.query.roleCode){
      this.$set(this.submitForm, `roleCode`, this.$route.query.roleCode);
    }
  },
  methods: {
    // 提交表单
    handleSubmitForm() {
      this.$refs.submitForm.validate((valid)=> {
        if(valid) {
          savaIframeApi({
            ...this.submitForm,
          }).then((res)=> {
            if(res.code === `20000`){
              this.resetForm();
            }
          })
        }
      })
    },
    // 重置表单
    resetForm() {
      this.$refs.submitForm.resetFields();
    },
  },
};
</script>

<style scoped lang="scss">

</style>
